package cn.wlinker.video.monitor.utils;

import cn.wlinker.video.monitor.domain.dto.MonitorDeviceDTO;
import cn.wlinker.video.monitor.domain.dto.PlayUrlDTO;
import cn.wlinker.video.monitor.domain.vo.VideoVO;
import cn.wlinker.video.monitor.service.IVideoBrandEnum;

import java.util.List;

/**
 * @author gxsjx
 * @version 1.0
 * @date 2022/11/9
 */
public class VideoUtils {
    /**
     * 根据获取到的dto开始构建播放流
     *
     * @return
     */
    public static VideoVO getVideoByMonitorType(String videoId, PlayUrlDTO playUrlDTO) {
        MonitorDeviceDTO monitorDeviceDtoById = VideoKeyUtils.getMonitorDeviceDtoById(videoId);
        IVideoBrandEnum videoBrandEnum = IVideoBrandEnum.getOne(monitorDeviceDtoById.getMonitorType());
        return videoBrandEnum.buildStream(monitorDeviceDtoById, playUrlDTO);
    }

    /**
     * 根据获取到的dto开始构建播放流
     *
     * @return
     */
    public static VideoVO getVideoByDto(MonitorDeviceDTO dto,PlayUrlDTO playUrlDTO) {
        IVideoBrandEnum videoBrandEnum = IVideoBrandEnum.getOne(dto.getMonitorType());
        return videoBrandEnum.buildStream(dto,playUrlDTO);
    }

    /**
     * 根据获取到的dto开始构建播放流
     *
     * @param dtos 设备列表
     * @return
     */
    public static List<VideoVO> getVideoListByDto(List<MonitorDeviceDTO> dtos,PlayUrlDTO playUrlDTO) {
        BuildStreamThreadPoolUtils<VideoVO> pool = new BuildStreamThreadPoolUtils<>();
        for (MonitorDeviceDTO dto : dtos) {
            IVideoBrandEnum videoBrandEnum = IVideoBrandEnum.getOne(dto.getMonitorType());
            pool.submit(() -> videoBrandEnum.buildStream(dto,playUrlDTO));
        }
        return pool.get();
    }
}
